package br.com.ceped.controlador;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Expression;
import org.hibernate.criterion.Restrictions;

import br.com.ceped.dao.Dao;
import br.com.ceped.dao.IDao;
import br.com.ceped.modelo.Reserva;
import br.com.ceped.modelo.Reserva_PK;

public class ControladorReserva implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public void cadastrar_reserva(Reserva reserva,Session s){
		IDao<Reserva> dao = new Dao<Reserva>(s, Reserva.class);
		dao.saveOrUpdate(reserva);
	}
	
	public void remover_reserva(Reserva reserva,Session s){
		IDao<Reserva> dao = new Dao<Reserva>(s, Reserva.class);
		dao.delete(reserva);
	}
	
	public void editar_reserva(Reserva reserva,Session s){
		IDao<Reserva> dao = new Dao<Reserva>(s, Reserva.class);
		dao.update(reserva);
	}
	
	public Reserva procurar_reserva(Reserva_PK reserva_PK,Session s){
		IDao<Reserva> dao = new Dao<Reserva>(s, Reserva.class);
		return dao.load(reserva_PK);
	}
	
	public List<Reserva> listar_reserva(Session s){
		IDao<Reserva> dao = new Dao<Reserva>(s, Reserva.class);
		return dao.list();
	}
    
	@SuppressWarnings("unchecked")
	public List<Reserva> listar_reservas_por_data(String nome_campo,Date data,Date dataFinal, Session s){
	Criteria c = s.createCriteria(Reserva.class);
	c.add(Expression.between(nome_campo, data, dataFinal));
	c.add(Restrictions.not(Expression.eq("condicao","devolvido")));
	c.setCacheable(true);
	return c.list();
	}
	
	@SuppressWarnings("unchecked")
	public List<Reserva> listar_reservas_por_data(String nome_campo,Date data,Date dataFinal,String nome_campo2,String campo, Session s){
	Criteria c = s.createCriteria(Reserva.class);
	c.add(Expression.between(nome_campo, data, dataFinal));
	c.add(Expression.eq(nome_campo2,campo));
	c.setCacheable(true);
	return c.list();
}
}
